package com.schoolcloud.serve.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.serve.dto.AttributeAndValuesDTO;
import com.schoolcloud.serve.entity.SkuAttribute;
import com.schoolcloud.serve.query.SkuAttributeQuery;
import com.schoolcloud.serve.service.SkuAttributeService;
import com.schoolcloud.serve.mapper.SkuAttributeMapper;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hongmizfb
 * @description 针对表【sku_attribute(商品属性表)】的数据库操作Service实现
 * @createDate 2025-04-12 17:11:02
 */
@Service
public class SkuAttributeServiceImpl extends ServiceImpl<SkuAttributeMapper, SkuAttribute>
        implements SkuAttributeService {

    @Override
    public PageDTO<SkuAttribute> getSkuAttributePage(SkuAttributeQuery query) {
        return MpPageUtil.of(getSkuAttributeMPPage(query), SkuAttribute.class);
    }
    @Override
    public Page<SkuAttribute> getSkuAttributeMPPage(SkuAttributeQuery query) {
        String categoryId = query.getCategoryId();
        String attributeType = query.getAttributeType();
        return lambdaQuery().eq(StrUtil.isNotBlank(categoryId), SkuAttribute::getCategoryId, categoryId).eq(StrUtil.isNotBlank(attributeType), SkuAttribute::getAttrType, attributeType).page(query.toMpPage());
    }
    @Override
    public List<SkuAttribute> getSkuAttributeByCategoryId(String categoryId) {
        return lambdaQuery().eq(SkuAttribute::getCategoryId, categoryId).list();
    }

    @Override
    public List<SkuAttribute> getSaleSkuAttributeByCategoryId(String categoryId) {
        return lambdaQuery().eq(SkuAttribute::getCategoryId, categoryId).ne(SkuAttribute::getAttrType, 1).list();
    }

}




